package homework6;

import roborl.Action;
import roborl.Decision;
import roborl.DiscreteValueApr;
import roborl.RobotState;

public class Homework {
	public static void main(String s[]) {

		DiscreteValueApr apr = new DiscreteValueApr(SimpleRobo.as);
		Decision decision = new Decision(apr, new SimpleRobo(5, 4));
		for (int i = 0; i < 50; i++) {
			SimpleRobo robo = new SimpleRobo(5, 4);
			RobotState lastState = null;

			while (true) {
				lastState = robo.getState(robo);
				// Action act = decision.getAction(robo);
				Action act = null;
				double dec = Math.random();
				if (dec < 0.25)
					act = SimpleRobo.up;
				else if (dec < 0.5)
					act = SimpleRobo.down;
				else if (dec < 0.75)
					act = SimpleRobo.left;
				else
					act = SimpleRobo.right;

				robo.takeAction(act);
				decision.learn(lastState, robo.getState(robo), act, 1, 0.9);

				if (robo.getX() == 4 && robo.getY() == 3)
					break;
			}

		}
		for (int j = 0; j < 4; j++) {
			for (int xx = 0; xx < 5; xx++) {
				SimpleRobo rb = new SimpleRobo(5, 4);
				rb.setX(xx);
				rb.setY(j);
				Action a = decision.getAction(rb,0);
				// if (apr.getBestValue(rb) < 0.01)
				// System.out.print("\t|");
				// else
				System.out.print("\t("
						+ (float) ((int) (apr.getBestValue(rb) * 10)) / 10.0f
						+ ")" + a);

			}
			System.out.println();
		}
		System.out.println();

	}
}
